<template>
  <nav class="sidebar">
    <ul class="menu">
      <li>
        <div class="menu-item" @click="navigateTo('all-files')">
          <el-icon><Folder /></el-icon>
          <span>全部文件</span>
        </div>
        <ul class="submenu" v-if="activeMenu === 'all-files'">
          <li v-for="item in fileTypes" :key="item.id">
            <div class="submenu-item" @click.stop="navigateTo(`all-files/${item.id}`)">
              <el-icon><component :is="item.icon" /></el-icon>
              {{ item.name }}
            </div>
          </li>
        </ul>
      </li>
      <li>
        <div class="menu-item" @click="navigateTo('recycle')">
          <el-icon><Delete /></el-icon>
          <span>回收站</span>
        </div>
      </li>
      <li>
        <div class="menu-item" @click="navigateTo('personal')">
          <el-icon><User /></el-icon>
          <span>我的</span>
        </div>
      </li>
    </ul>
  </nav>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Folder,
  Delete,
  User,
  Picture,
  VideoCamera,
  Document,
  Headset,
} from '@element-plus/icons-vue'
const router = useRouter()
const activeMenu = ref('all-files')

const fileTypes = ref([
  { id: 'images', name: '图片', icon: Picture },
  { id: 'audio', name: '音频', icon: Headset },
  { id: 'video', name: '视频', icon: VideoCamera },
  { id: 'documents', name: '文档', icon: Document },
  { id: 'others', name: '其他', icon: Folder }
])

const navigateTo = (path) => {
  activeMenu.value = path.split('/')[0]
  if (path === 'recycle') {
    router.push({ path: '/recycle' })
  } else if (path === 'personal') {
    router.push({ path: '/personal' })
  } else {
    router.push({ path: `/${path}` })
  }
}
</script>

<style scoped>
.sidebar {
  width: 200px;
  background-color: #e6eef8;
  color: black;
  height: 100%;
  overflow-y: auto;
}

.menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-item, .submenu-item {
  padding: 12px 20px;
  cursor: pointer;
  transition: background-color 0.3s;
  display: flex; /* 使用 flex 布局 */
  align-items: center; /* 垂直居中 */
  gap: 10px; /* 设置图标和文字之间的间隔 */
}

.menu-item:hover, .submenu-item:hover {
  background-color: #9fcbe3;
}

.submenu {
  list-style: none;
  padding-left: 20px;
  margin: 0;
  background-color:  #e6eef8;
}

.submenu-item {
  padding-left: 30px;
}
</style>